package com.xsky.common.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;


public class HibernateUtil 
{
	private static Log log = LogFactory.getLog(HibernateUtil.class);
	private static final SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
	public static final ThreadLocal session = new ThreadLocal();
	public static Session currentSession()
	{
		Session s = (Session)session.get();
		if(s == null)
		{
			s = sessionFactory.openSession();
			session.set(s);
		}
		return s;
	}
	public static void closeSession()
	{
		Session s = (Session)session.get();
		if(s!=null)
		{
			s.close();
		}
		session.set(null);
	}
}
